- Solving Linear Differential Equations with Xi -
The routine ode_solve(func,y,t[,abs_tol][,rel_tol]) solves ordinary differential equations. func describes the equation, y contains an array of initial values at point t[0] and the array t represents the independent variable. The optional variables abs_tol and rel_tol are the absolute and the relative tolerance parameters. A nice example is the damped harmonic oszillator - in this case the differential equation y''+0.12*y'+y=0 with the initial conditions y[0]=0.7, y'[0]=1. Because ode_solve can solve equations of first order only you must translate this equation of second order into two equations of first order:
y0'=y1 y1'=-y0-0.12*y1Then You can input:
( 1)>t=dincarr(1000)/30; ( 2)>y=ode_solve([(y;t)->y':y'={y[1],-y[0]-0.12*y[1]};],{0.7,1},t);With
( 3)>plot(t,y[0,*],\line);you obtain the following output (after reduction of the window):